package com.vanysoft.business.sys.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.vanysoft.business.sys.entity.Notify;
import com.vanysoft.business.sys.service.NotifyService;
import com.vanysoft.framework.base.action.BaseController;
import com.vanysoft.framework.exception.VanySoftBaseException;
import com.vanysoft.framework.messagesource.MessageCodeConstant;
import com.vanysoft.framework.utils.JSONResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 用户管理
 *
 * @author qi_ma
 */
@RequestMapping("/sys/notify")
@Controller
public class NotifyController extends BaseController {
    @Resource
    private NotifyService notifyService;

    @RequestMapping("notify")
    public String user() {
        return "sys/notify";
    }

    @RequestMapping("addNotify")
    @ResponseBody
    public JSONResponse addNotify(Notify notify) {
        notify.setNotifyDate(LocalDateTime.now());
        notifyService.insert(notify);
        return new JSONResponse();
    }

    @RequestMapping("modifyNotify")
    @ResponseBody
    public JSONResponse modifyNotify(Notify notify) {
        notifyService.updateById(notify);
        return new JSONResponse();
    }

    @RequestMapping(value = "/list", method = {RequestMethod.GET})
    @ResponseBody
    public JSONResponse getRoleInfo(Page<Notify> page) throws VanySoftBaseException {
        page = notifyService.selectAll(page);
        return new JSONResponse(MessageCodeConstant.RTN_CODE_SUCCESS, page);
    }

}
